package com.ctf.soft.ms.service.manage.impl;

import com.ctf.soft.ms.dao.dto.manage.LoginUser;
import com.ctf.soft.ms.dao.mapper.manage.UserMapper;
import com.ctf.soft.ms.dao.model.manage.User;
import com.ctf.soft.ms.service.impl.BaseService;
import com.ctf.soft.ms.utils.ResourceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ctf.soft.ms.service.manage.IUserService;

import java.util.List;
import java.util.Map;

/**
 * 名称： UserServiceImpl<br>
 * 描述： 系统用户业务处理实现类<br>
 * 最近修改时间：2015/7/31 11:15<br>
 * 修改说明：
 *
 * @author jiajl
 */
@Service
public class UserServiceImpl extends BaseService<User> implements IUserService {

    @Autowired
    private UserMapper userMapper;

    public List<User> loadPageList(Map<String, Object> map) {
        int page = Integer.valueOf(map.get("page").toString());
        int rows = Integer.valueOf(map.get("rows").toString());
        int beginRowNum = (page - 1) * rows;
        int endRowNum = page * rows;
        map.put("beginRowNum", beginRowNum);
        map.put("endRowNum", endRowNum);
        map.put("db", ResourceUtil.getString("DATA_ALIAS"));
        return userMapper.queryForPageList(map);
    }

    public int getPageCount(Map<String, Object> map) {
        return userMapper.queryForPageCount(map);
    }

    public LoginUser loadLogin(String account, String pwd) {
        LoginUser loginUser = null;
        User params = new User();
        params.setAccount(account);
        params.setPassword(pwd);
        User user = selectByEntity(params);
        if (user != null) {
            loginUser = new LoginUser();
            loginUser.setId(user.getId());
            loginUser.setRealName(user.getRealName());
            loginUser.setAccount(user.getAccount());
            loginUser.setWorkNumber(user.getWorkNumber());
            loginUser.setDefaultLeader(user.getDefaultLeader());
            loginUser.setDefaultLeaderCode(user.getDefaultLeaderCode());
            loginUser.setDefaultPost(user.getDefaultPost());
            loginUser.setDefaultPostCode(user.getDefaultPostCode());
            loginUser.setDefaultDept(user.getDefaultDept());
            loginUser.setDefaultDeptCode(user.getDefaultDeptCode());
            loginUser.setDefaultOrg(user.getDefaultOrg());
            loginUser.setDefaultOrgCode(user.getDefaultPostCode());
            loginUser.setImgPath(user.getImgPath());
            loginUser.setStatus(user.getStatus());
        }
        return loginUser;
    }
}
